package com.yunnuo.system.users.service.impl;

import com.yunnuo.system.comm.util.Page;
import com.yunnuo.system.comm.util.Where;
import com.yunnuo.system.users.dao.IUserRoleDao;
import com.yunnuo.system.users.entity.UserRole;
import com.yunnuo.system.users.service.IUserRoleService;
import org.hibernate.service.spi.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by w_weihf on 2018/7/20.
 */
@Service
public class UserRoleServiceImpl implements IUserRoleService {

    @Autowired
    private IUserRoleDao userRoleDao;

    @Override
    public void addVO(UserRole vo) throws ServiceException {

    }

    @Override
    public void updateVO(UserRole vo) throws ServiceException {

    }

    @Override
    public void delList(String[] ids) throws ServiceException {
    }

    @Override
    public void deleteVo(String id) throws ServiceException {

    }

    @Override
    public List<UserRole> findList() throws ServiceException {
        return null;
    }

    @Override
    public List<?> findList(UserRole vo, String other) throws ServiceException {
        return null;
    }




    @Override
    public UserRole findVO(String id) throws ServiceException {
        return null;
    }

    @Override
    public List selectCountUserRoleByRoleId(String roleId) {
        return userRoleDao.findAllByRoleId(roleId);
    }

    /**
     * 保存用户权限
     * @param userRoles
     * @return 0失败   1成功
     */
    @Override
    public int save( List<UserRole> userRoles) {
        int flag=1;
        for (UserRole userRole:userRoles) {
            UserRole ur=userRoleDao.save(userRole);
            if(ur==null ||  ur.getId()==null || "".equals(ur.getId())){
                flag=0;
                break;
            }
        }
        return flag;
    }

    /**
     * 根据用户ID删除所有的角色
     * @param id
     */
    @Override
    public void deleteuserRoleByUserId(String id) {
        userRoleDao.deleteByUserId(id);
    }

}
